#include "include/event_manager.h"

#include <sys/epoll.h>

namespace unet {
class Epoll : public EventManager {
 public:
  Epoll();
  ~Epoll();

  bool Init();

  bool Add(Event* ev);
  bool Mod(Event* ev);
  void Del(Event* ev);

  void Loop();
  void LoopInAnotherThread();

  void Stop();

 private:
  int32 ep_fd_;
  bool stop_;

  typedef std::map<int32, Event*> EvMap;
  typedef EvMap::iterator EvIter;

  EvMap ev_map_;
  std::vector<epoll_event> events_;

  bool CheckEvent(Event* ev);

  uint8 ConvertToEvent(uint8 event);
  uint8 ConvertFromEvent(uint8 event);

  DISALLOW_COPY_AND_ASSIGN(Epoll);
};
}
